package com.attilax.net.ftp;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

import org.apache.ftpserver.FtpServer;
import org.apache.ftpserver.FtpServerFactory;
import org.apache.ftpserver.ftplet.Authority;
import org.apache.ftpserver.ftplet.FtpException;
import org.apache.ftpserver.ftplet.User;
import org.apache.ftpserver.usermanager.impl.BaseUser;
import org.apache.ftpserver.usermanager.impl.WritePermission;

import com.attilax.collection.listBuilder;

public class ftpapache {

	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws FtpException {

		// BaseUser BaseUser1 =
		// BaseUserBldr.$().setName("anonymous").setHomeDirectory("/")
		// .setAuthorities(listBuilder.<Authority> $().add(new
		// WritePermission()).build()).build();
		
		FtpServerFactoryBld.$().getUserManager()
				.save(BaseUserBldr.$().setName("anonymous").setHomeDirectory("/")
						.setAuthorities(listBuilder.<Authority> $().add(new WritePermission()).build()).build())
				.build().createServer().start();

		// unless recyel,if use anoather class ,should be a
		// thred. to use start

		// t2();

	}

	private static FtpServerFactory build() {
		// TODO Auto-generated method stub
		return null;
	}

	private static void iniblockver() throws FtpException {
		new FtpServerFactory() {
			{
				this.getUserManager().save(new BaseUser() {
					{
						this.setName("anonymous");
						this.setHomeDirectory("/");
						this.setAuthorities(listBuilder.<Authority> $().add(new WritePermission()).build());
					}
				});
			}
		}.createServer().start();
	}

	private static void t2() throws FtpException {
		FtpServerFactory serverFactory = new FtpServerFactory();
		serverFactory.getUserManager().save((User) ((Function) (Object) -> {
			BaseUser user = new BaseUser();
			user.setName("anonymous");
			user.setHomeDirectory("c:/");

			user.setAuthorities(listBuilder.<Authority> $().add(new WritePermission()).build());

			return user;
		}).apply(null));
		FtpServer server = serverFactory.createServer();
		server.start(); // unless recyel,if use anoather class ,should be a
						// thred. to use start

		// Function f2=(Object)->{
		// return Object;};
		// Function o=(Object)->{ return null;};
		// Object o2= ((Function)(Object)->{ return null;}).apply(null);
		// Builders.$().build2((Object)->{ return null;});
	}

}
